﻿using System;
using System.Data;
using System.Text;

namespace ltModel.DAL
{
    /// <summary>
    /// 数据访问类userTeam。
    /// </summary>
    public class userTeam
    {
        public userTeam()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from lt_userTeam where user_id=" + id + "");
            return DataObject.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ltModel.Model.userTeam model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into lt_userTeam(");
            strSql.Append("user_id,sh,tj,ad,del,lmqx,funcqx,info");
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append("" + model.user_id + ",");
            strSql.Append("" + model.sh + ",");
            strSql.Append("" + model.tj + ",");
            strSql.Append("" + model.add + ",");
            strSql.Append("" + model.del + ",");
            strSql.Append("'" + model.lmqx + "',");
            strSql.Append("'" + model.funcqx + "',");
            strSql.Append("'" + model.info + "'");
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DataObject.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ltModel.Model.userTeam model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update lt_userTeam set ");
            if (model.sh != null)
                strSql.Append("sh=" + model.sh + ",");
            if (model.tj != null)
                strSql.Append("tj=" + model.tj + ",");
            if (model.add != null)
                strSql.Append("ad=" + model.add + ",");
            if (model.del != null)
                strSql.Append("del=" + model.del + ",");
            if (model.lmqx != null)
                strSql.Append("lmqx='" + model.lmqx + "',");
            if (model.funcqx != null)
                strSql.Append("funcqx='" + model.funcqx + "',");
            strSql.Append(" info=info ");
            strSql.Append(" where user_id=" + model.user_id + "");
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete lt_userTeam ");
            strSql.Append(" where user_id=" + id);
            if (DataObject.ExecuteSql(strSql.ToString()) > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ltModel.Model.userTeam GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append(" [user_id],[sh],[tj],[ad],[del],[lmqx],[funcqx],[info] ");
            strSql.Append(" from lt_userTeam ");
            strSql.Append(" where user_id=" + id);
            ltModel.Model.userTeam model = new ltModel.Model.userTeam();
            DataSet ds = DataObject.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);

                if (ds.Tables[0].Rows[0]["sh"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["sh"].ToString() == "1") || (ds.Tables[0].Rows[0]["sh"].ToString().ToLower() == "true"))
                    {
                        model.sh = "1";
                    }
                    else
                    {
                        model.sh = "0";
                    }
                }

                if (ds.Tables[0].Rows[0]["tj"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["tj"].ToString() == "1") || (ds.Tables[0].Rows[0]["tj"].ToString().ToLower() == "true"))
                    {
                        model.tj = "1";
                    }
                    else
                    {
                        model.tj = "0";
                    }
                }

                if (ds.Tables[0].Rows[0]["ad"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["ad"].ToString() == "1") || (ds.Tables[0].Rows[0]["ad"].ToString().ToLower() == "true"))
                    {
                        model.add = "1";
                    }
                    else
                    {
                        model.add = "0";
                    }
                }

                if (ds.Tables[0].Rows[0]["del"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["del"].ToString() == "1") || (ds.Tables[0].Rows[0]["del"].ToString().ToLower() == "true"))
                    {
                        model.del = "1";
                    }
                    else
                    {
                        model.del = "0";
                    }
                }

                model.lmqx = ds.Tables[0].Rows[0]["lmqx"].ToString();
                model.funcqx = ds.Tables[0].Rows[0]["funcqx"].ToString();
                model.info = ds.Tables[0].Rows[0]["info"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [user_id],[sh],[tj],[ad],[del],[lmqx],[funcqx],[info] ");
            strSql.Append(" FROM lt_userTeam ");
            if (strWhere.Trim() != "")
            {

                strSql.Append(" where " + strWhere);
            }
            return DataObject.Query(strSql.ToString());
        }

        #endregion  成员方法
    }
}